package com.ruoyi.gateway.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.gateway.service.GatewayMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/api/monitor")
public class MonitorController {

    @Autowired
    private GatewayMonitorService monitorService;

    /**
     * 获取系统统计信息
     */
    @GetMapping("/stats")
    public AjaxResult getSystemStats() {
        return AjaxResult.success(monitorService.getSystemStats());
    }

    /**
     * 获取连接设备列表
     */
    @GetMapping("/devices")
    public AjaxResult getConnectedDevices() {
        return AjaxResult.success(monitorService.getConnectedDevices());
    }

    /**
     * 获取平台客户端列表
     */
    @GetMapping("/platformClients")
    public AjaxResult getPlatformClients() {
        return AjaxResult.success(monitorService.getPlatformClients());
    }

    /**
     * 获取最近消息流水
     */
    @GetMapping("/messages/recent")
    public AjaxResult getRecentMessages(@RequestParam(defaultValue = "50") int limit) {
        return AjaxResult.success(monitorService.getRecentMessageFlow(limit));
    }

    /**
     * 搜索消息流水
     */
//    @GetMapping("/messages/search")
//    public TableDataInfo searchMessages(MessageFlowQuery query) {
//        startPage();
//        List<MessageFlowLog> list = messageFlowLogMapper.selectByQuery(query);
//        return getDataTable(list);
//    }
}
